package uk.co.richardwkirk.parkrun.web;


public class ParkrunURLGenerator {

	public static final String PARKRUN_DEFAULT_UK_SITE_URL = "http://www.parkrun.org.uk/";
	
	private String siteURL = null;
	
	public enum ParkrunWebPages {
		Home,
		LatestResults,
		News, 
		Course, 
		NewsFeed
	}

	/**
	 * Create a generator using the site URL provided as the base.
	 * @param siteURL
	 */
	public ParkrunURLGenerator(String siteURL) {
		this.siteURL = siteURL;
	}

	@Deprecated
	public static String createUKSiteURL(String pagename) {
		StringBuilder url = new StringBuilder();
		url.append(PARKRUN_DEFAULT_UK_SITE_URL);
		url.append(pagename);
		return url.toString();
	}
	

	@Deprecated
	public static String createUKEventResultURL(String parkrunName, int eventNumber) {
		StringBuilder eventURL = new StringBuilder();
		eventURL.append(PARKRUN_DEFAULT_UK_SITE_URL);
		eventURL.append(parkrunName);
		eventURL.append("/results/weeklyresults/?runSeqNumber=");
		eventURL.append(eventNumber);
		return eventURL.toString();
	}
	

	@Deprecated
	public static String createLatestUKEventResultsURL(String parkrunName) {
		StringBuilder eventURL = new StringBuilder();
		eventURL.append(PARKRUN_DEFAULT_UK_SITE_URL);
		eventURL.append(parkrunName);
		eventURL.append("/results/latestresults/");
		return eventURL.toString();
	}

	
	@Deprecated
	public static String createAthleteSummaryURL(long athleteNumber) {
		return createAthleteSummaryURL(String.valueOf(athleteNumber));
	}
	
	@Deprecated
	public static String createAthleteSummaryURL(String athleteNumber) {
		StringBuilder eventURL = new StringBuilder();
		eventURL.append(PARKRUN_DEFAULT_UK_SITE_URL);
		eventURL.append("results/athleteresultshistory/?athleteNumber=");
		eventURL.append(athleteNumber);
		return eventURL.toString();
	}


	public String createEventURL(String parkrun, ParkrunWebPages pageType) {
		StringBuilder url = new StringBuilder();
		url.append(siteURL).append("/");
		url.append(parkrun).append("/");
		url.append(createPageURL(pageType));
		return url.toString();
	}
	
	public String createRegionalURL(ParkrunWebPages pageType) {
		StringBuilder url = new StringBuilder();
		url.append(siteURL).append("/");
		url.append(createPageURL(pageType));
		return url.toString();
	}
	
	private String createPageURL(ParkrunWebPages pageType) {
		StringBuilder url = new StringBuilder();
		switch (pageType) {
			case LatestResults:
				url.append("results/latestresults/");
				break;
			case Course:
				url.append("course/");
				break;
			case News:
				url.append("news/");
				break;
			case NewsFeed:
				url.append("feed/");
				break;
			case Home:
			default:
				break;
		}
		return url.toString();
	}
	

	
}
